-module(all_serv1).
-behaviour(gen_server).
-export([start_link/0]).
-export([init/1,
         handle_call/3,
         handle_cast/2,
         handle_info/2,
         code_change/3,
         terminate/2]).
-define(SERVER, ?MODULE). % macro that just defines this module as server
-record(state, {name, count}). % server state


%% API
start_link() ->
    gen_server:start({local, ?SERVER}, ?MODULE, [], []).


%% Gen server
init([]) ->
    {ok, #state{name=?SERVER, count=0}}.

handle_call(stop, _From, State) ->
    Reply = ok,
    {stop, normal, Reply, State};

handle_call(_Request, _From, State) ->
    NewState = #state{count=(State#state.count+1)},
    Reply = ok,
    {reply, Reply, NewState}.

handle_cast(stop, State) ->
    Reply = ok,
    {stop, Reply, State};

handle_cast(_Msg, State) ->
    {noreply, State}.

handle_info(Msg, State) ->
    io:format("Unknown msg: ~p~n", [Msg]),
    {noreply, State}.

code_change(_OldVsn, State, _Extra) ->
    {ok, State}.

terminate(_Reason, _State) ->
    ok.